//
//  ZH_ShareBoxCollectionViewCell.m
//  HenticaSample
//
//  Created by zhangliwen on 2018/5/3.
//  Copyright © 2018年 HenticaSample. All rights reserved.
//

#import "ZH_ShareBoxCollectionViewCell.h"
@interface ZH_ShareBoxCollectionViewCell()
///标题
@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic,weak)UIButton *button;

@end
@implementation ZH_ShareBoxCollectionViewCell
///注册cell
+(void)registerCollectionView:(UICollectionView*)collectionView
{
    [collectionView registerClass:[ZH_ShareBoxCollectionViewCell class] forCellWithReuseIdentifier:@"ZH_ShareBoxCollectionViewCell"];
}

///创建
+(id)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return [collectionView dequeueReusableCellWithReuseIdentifier:@"ZH_ShareBoxCollectionViewCell" forIndexPath:indexPath];
}
///更新 ui
- (void)updateUiForIcon:(NSString *)icon andTitle:(NSString *)title
{
    [self.iconImageView setImageForName:icon];
    self.titleLabel.text = title;
}
- (void)updataUI:(NSDictionary *)data{
    if (data) {
        [self.button setTitle:data[@"spec_name"] forState:UIControlStateNormal];
    }
}
- (void)selectedButton:(BOOL)isbool{
    self.button.selected = isbool;
}
///加载子视图约束
-(void)loadSubviewConstraints
{
//    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.center.equalTo(self.contentView);
//    }];
//
//    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.contentView).offset(FITWITH(10));
//        make.right.equalTo(self.contentView).offset(FITWITH(-10));
//        make.top.equalTo(self.iconImageView.mas_bottom).offset(FITHEIGHT(6));
//    }];
    [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.contentView);
        make.height.mas_equalTo(FITSCALE(34));
        make.width.mas_equalTo(FITSCALE(50));
    }];
}
- (void)button:(UIButton *)btn{
//    if(btn.isSelected){
//        [btn setSelected:NO];
//    }else{
//        //选中
//        [btn setSelected:YES];
//    }
//    if (self.onButtonClick) {
//        self.onButtonClick(btn.selected);
//    }
}
- (void)setSelectedState:(BOOL)selected{
    self.button.selected = selected;
}
#pragma mark - getter,setter
//- (UIImageView *)iconImageView
//{
//    if(!_iconImageView){
//        UIImageView *image = [UIImageView createImageViewWithName:@""];
//        image.contentMode = UIViewContentModeScaleAspectFill;
//        image.clipsToBounds = YES;
//        [self.contentView addSubview:_iconImageView = image];
//    }
//    return _iconImageView;
//}
//
//
- (UILabel *)titleLabel
{
    if(!_titleLabel){
        UILabel *label = [UILabel createLabelWithText:@"" font:kFontSize_28];
        [label setTextAlignment:NSTextAlignmentCenter];
        [self.contentView addSubview:_titleLabel = label];
    }
    return _titleLabel;
}
- (UIButton *)button{
    if (!_button) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"" target:self action:@selector(button:)];
        button.userInteractionEnabled = NO;
        button.backgroundColor = kCommonBackgroudColor;
        [button setTitleColor:kFontColorRed forState:UIControlStateSelected];
        [button setTitleColor:kFontColorBlack forState:UIControlStateNormal];
        button.layer.cornerRadius = FITSCALE(14);
        button.layer.masksToBounds = YES;
        button.clipsToBounds = YES;
        [self.contentView addSubview:_button = button];
    }
    return _button;
}
@end
